const { DataTypes, Sequelize } = require("sequelize");
const sequelize = require("./sequelizeBaseConfig.js");

const OperationLog = sequelize.define(
  "OperationLog",
  {
    id: {
      type: DataTypes.BIGINT,
      comment: "ID",
      autoIncrement: true, //自增
      primaryKey: true, //主键
    },
    created_at: {
      type: DataTypes.DATE,
      comment: "创建时间",
      defaultValue: Sequelize.literal("CURRENT_TIMESTAMP"), //如果没有设置该字段的值则使用默认
    },
    updated_at: {
      type: DataTypes.DATE,
      comment: "更新时间",
      defaultValue: Sequelize.literal(
        "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
      ),
    },
    opt_module: {
      type: DataTypes.STRING(50),
      allowNull: false,
      comment: "操作模块",
    },
    opt_type: {
      type: DataTypes.STRING(50),
      allowNull: false,
      comment: "操作类型",
    },
    opt_method: {
      type: DataTypes.STRING(100),
      allowNull: false,
      comment: "操作方法",
    },
    opt_url: {
      type: DataTypes.STRING(255),
      allowNull: false,
      comment: "操作URL",
    },
    opt_desc: {
      type: DataTypes.STRING(255),
      allowNull: false,
      comment: "操作描述",
    },
    request_param: {
      type: DataTypes.TEXT,
      allowNull: true,
      comment: "请求参数",
    },
    request_method: {
      type: DataTypes.TEXT,
      allowNull: true,
      comment: "请求方法",
    },
    response_data: {
      type: DataTypes.TEXT,
      allowNull: true,
      comment: "响应数据",
    },
    user_id: {
      type: DataTypes.INTEGER,
      allowNull: false,
      comment: "用户ID",
    },
    nickname: {
      type: DataTypes.STRING,
      allowNull: false,
      comment: "用户昵称",
    },
    ip_address: {
      type: DataTypes.STRING,
      allowNull: false,
      comment: "操作IP",
    },
    ip_source: {
      type: DataTypes.STRING,
      allowNull: false,
      comment: "操作地址",
    },
  },
  { tableName: "operation_log", timestamps: false }
);

module.exports = {
  OperationLog,
};
